import urllib.parse as parse
import urllib.request as request

if __name__ == '__main__':

    # http post 请求
    url = "http://httpbin.org/post"
    headers = {
        # 伪装一个火狐浏览器
        "User-Agent": 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
        "host": 'httpbin.org'
    }
    dict = {
        "name": "Germey"
    }
    data = bytes(parse.urlencode(dict), encoding="utf8")
    req = request.Request(url=url, data=data, headers=headers, method="POST")
    response = request.urlopen(req)
    print(response.read().decode("utf-8"))

    # http 代理
    proxy_handler = request.ProxyHandler({'http': 'http://121.193.143.249:80/'})
    opener = request.build_opener(proxy_handler)
    r = opener.open('http://httpbin.org/ip')
    print(r.read())
